package com.skycong.hello77.tabfragment.viewmodel;

import android.app.Activity;
import android.content.Context;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.skycong.hello77.R;
import com.skycong.hello77.common.viewpager.MyViewPager;
import com.skycong.hello77.tabfragment.activity.TabFragmentActivity;

/**
 * Created by Kiki on 2018/6/21.
 */

public class TabFragmentViewModel {
    public MyViewPager viewpager;
    public LinearLayout layout_lable, layout_signin, layout_footprint;// tab横线
    public ImageView img_signin, img_footprint;// tab横线
    public TextView tv_signin, tv_footprint;// tab标题
    private ImageView[] imgs;
    private TextView[] tvs;
    public TabFragmentViewModel(Context context){
        Activity view = (Activity) context;
        viewpager = (MyViewPager) view.findViewById(R.id.viewpager);
        layout_lable = (LinearLayout) view.findViewById(R.id.layout_lable);
        layout_signin = (LinearLayout) view.findViewById(R.id.layout_signin);
        layout_footprint = (LinearLayout) view.findViewById(R.id.layout_footprint);
        img_signin = (ImageView) view.findViewById(R.id.img_signin);
        img_footprint = (ImageView) view.findViewById(R.id.img_footprint);
        tv_signin = (TextView) view.findViewById(R.id.tv_signin);
        tv_footprint = (TextView) view.findViewById(R.id.tv_footprint);

        imgs = new ImageView[]{img_signin, img_footprint};
        tvs = new TextView[]{tv_signin, tv_footprint};
    }

    public void setListener(TabFragmentActivity listener){
        layout_signin.setOnClickListener(listener);
        layout_footprint.setOnClickListener(listener);
    }

    /**
     * 设置tab选中
     *
     * @param page
     */
    public void setSelected(int page) {
        setAllUnSelected();
        imgs[page].setSelected(true);
        tvs[page].setSelected(true);
    }

    private void setAllUnSelected() {
        for (ImageView i : imgs) {
            i.setSelected(false);
        }
        for (TextView t : tvs) {
            t.setSelected(false);
        }
    }
}
